﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AdministrationWeb.Administration
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            txtFirstName.Focus();
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Server.Transfer("default.aspx");
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            SqlDataSource2.DataBind();
            GridView1.Visible = true;
        }

        protected void btnEdit_Click(object sender, EventArgs e)
        {
            Server.Transfer("AddUser.aspx");
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            User userSelected = new User();
            try
            {
                userSelected.graduationYear = Convert.ToInt32(GridView1.SelectedRow.Cells[7].Text);
            }
            catch
            {
                userSelected.graduationYear = 0;
            }
            userSelected.emailAddress = GridView1.SelectedRow.Cells[8].Text;
            userSelected.firstName = GridView1.SelectedRow.Cells[4].Text;
            userSelected.lastName = GridView1.SelectedRow.Cells[5].Text;
            try
            {
                userSelected.userID = Convert.ToInt32(GridView1.DataKeys[GridView1.SelectedIndex].Value.ToString());
            }
            catch
            {
                userSelected.userID = 0;
            }
            userSelected.userName = GridView1.SelectedRow.Cells[3].Text;
            try{
                userSelected.permission = Convert.ToChar(GridView1.SelectedRow.Cells[6].Text);
            }
            catch
            {
                userSelected.permission = 'S';
            }
            Session.Add("SelectedUser", userSelected);
            Server.Transfer("/Administration/AddUser.aspx");
        }

        protected void Button1_Click1(object sender, EventArgs e)
        {
        }
    }
}